package com.itheima.service.imp;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Resource
    private DeptMapper deptMapper;


    @Override
    public List<Dept> queryAll() {
        // 要准备所有部门列表：调用mapper得到所有部门列表
        List<Dept> deptList = deptMapper.queryAll();
        // 将结果数据进行处理:不需要处理，因为List<Dept> 里的数据 和API接口要求的响应数据完全符合
        return deptList;
    }

    @Override
    public void deleteByid(Integer id) {
        deptMapper.deleteByid(id);

    }

    @Override
    public void addDept(Dept dept) {
        // 补充创建时间和、修改时间
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.addDept(dept);
    }

    @Override
    public Dept findById(Integer id) {
        Dept dept = deptMapper.findById(id);
        return dept;
    }

    @Override
    public void updateByid(Dept dept) {
        // 补充修改时间
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateByid(dept);

    }


}